import request from './request'

// 轮播图数据类型（与后端PublicBannerResponse保持一致）
export interface Banner {
  id: number
  title: string
  image: string
  linkUrl?: string
  sortOrder: number
  position: 1 | 2
}

// 轮播图查询参数
export interface BannerQuery {
  position?: 1 | 2
  limit?: number
}

// 轮播图列表响应类型
export interface BannerListResponse {
  banners: Banner[]
  position: 1 | 2
}

export const bannerApi = {
  // 获取轮播图列表（公开接口）
  getBanners: (params?: BannerQuery) => {
    return request.get<BannerListResponse>('/api/public/banners', { params })
  },

  // 获取首页轮播图
  getHomeBanners: (limit = 5) => {
    return request.get<BannerListResponse>('/api/public/banners', { params: { position: 1, limit } })
  },

  // 获取指定位置的轮播图
  getBannersByPosition: (position: number, limit = 5) => {
    return request.get<BannerListResponse>('/api/public/banners', { params: { position, limit } })
  },

  // 获取轮播图详情
  getBannerById: (id: number) => {
    return request.get<Banner>(`/api/banners/${id}`)
  },

  // 记录轮播图点击
  recordBannerClick: (id: number) => {
    return request.post(`/api/banners/${id}/click`)
  }
}